//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: baseJs.imgUrl,
    goodsList: [],
    userData: [],
    task0: [{
        value: "观看视频",
        no: "观看视频",
        yes: "已观看",
        go: "观看视频>>",
        describe: "完成观看视频的任务即可获得系统的易码奖励！",
        active: false,
        zero: "",
        url: "/packageA/watchVideo/watchVideo"
      },
      {
        value: "购买商品",
        no: "首次购买商品（未完成）",
        yes: "首次购买商品（已完成）",
        go: "去购买>>",
        describe: "新用户第一次购买产品将会得到系统的易码奖赠！",
        active: false,
        zero: "",
        url: "../index/index"
      }
    ],
    task1: [{
        value: "签到",
        no: "签到",
        yes: "今天已签到",
        go: "去签到>>",
        describe: "签到可获得易码奖励，连续签到最多可拿50M奖励（价值50元）！",
        active: false,
        zero: "",
        url: "/packageA/goSign/goSign"
      },
      {
        value: "分享商品",
        no: "分享商品",
        yes: "今天已分享",
        go: "去分享>>",
        describe: "分享任意商品到朋友圈获得点击可得到易码奖励，每天仅限一次，快快分享吧!",
        active: false,
        zero: "",
        url: "../index/index"
      },
      {
        value: "邀请注册",
        no: "首次购买商品（未完成）",
        yes: "首次购买商品（已完成）",
        go: "去邀请>>",
        describe: "邀请一名新用户注册，可获得10M奖励！",
        active: false,
        zero: "0",
        num: "",
        url: "/packageA/goInvite/goInvite"
      },
      {
        value: "评价订单",
        no: "首次购买商品（未完成）",
        yes: "首次购买商品（已完成）",
        go: "去评价>>",
        describe: "对已购买的商品进行评价即可获得2M奖励，完成购买后不要忘记评价！",
        active: false,
        zero: "0",
        num: "",
        url: "/packageA/evaluateOrder/evaluateOrder"
      },
    ],
    // 
    uid: "",
    userType: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      uid: wx.getStorageSync('uid'),
      userType: wx.getStorageSync('userType')
    })
    this.GetUserTaskInfo();
    if (this.data.userType != 1) {
      this.GetAreaGoodsList();
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  
  // slideTap0
  slideTap0: function(e) {
    var task0 = this.data.task0;
    var task1 = this.data.task1;
    var value = e.currentTarget.dataset.value;
    for (var i = 0, len = task1.length; i < len; ++i) {
      task1[i].active = false
    }
    for (var i = 0, len = task0.length; i < len; ++i) {
      if (task0[i].value == value) {
        if (task0[i].active == true) {
          task0[i].active = false;
        } else {
          task0[i].active = true;
        }
      } else {
        task0[i].active = false
      }
    }
    this.setData({
      task0: task0,
      task1: task1,
    })
  },
  // slideTap1
  slideTap1: function(e) {
    var task0 = this.data.task0;
    var task1 = this.data.task1;
    var value = e.currentTarget.dataset.value;
    for (var i = 0, len = task0.length; i < len; ++i) {
      task0[i].active = false
    }
    for (var i = 0, len = task1.length; i < len; ++i) {
      if (task1[i].value == value) {
        if (task1[i].active == true) {
          task1[i].active = false;
        } else {
          task1[i].active = true;
        }
      } else {
        task1[i].active = false
      }
    }
    this.setData({
      task0: task0,
      task1: task1,
    })
  },
  //  GetUserTaskInfo
  GetUserTaskInfo: function() {
    var that = this;
    var uid = this.data.uid;
    var userData = this.data.userData;
    var task0 = this.data.task0;
    var task1 = this.data.task1;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetUserTaskInfo&UID=" + uid),
      success: function(res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        task0[0].zero = json.HaveStudyVideoNum;
        task0[1].zero = json.IsFinishedFirstPay;
        // 
        task1[0].zero = json.IsSign;
        task1[1].zero = json.IsGoodsShare;
        task1[2].num = json.LockUserNum;
        task1[3].num = json.GoodsCommentNum;
        that.setData({
          task0: task0,
          task1: task1,
        })
      }
    })
  },
  //  GetAreaGoodsList
  GetAreaGoodsList: function() {
    var that = this;
    var goodsList = this.data.goodsList;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetAreaGoodsList&PageSize=10&PageIndex=1"),
      success: function(res) {
        goodsList = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        that.setData({
          goodsList: goodsList,
        })
        console.log(goodsList);
      }
    })
  },
})